<?php
// +----------------------------------------------------------------------
// | B5Yii2CMF V3.0 [快捷通用基础管理开发平台]
// +----------------------------------------------------------------------
// | Author: 冰舞 <357145480@qq.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace common\models\system;


/**
 * This is the model class for table "sys_test_data".
 *
 * @property int $id
 * @property int|null $user_id 用户id
 * @property int|null $struct_id 部门id
 * @property string|null $title
 * @property string|null $remark
 * @property string|null $status
 * @property string|null $create_time
 * @property string|null $update_time
 * @property-read Struct|null $struct
 * @property-read Admin|null $user
 */
class TestData extends \yii\db\ActiveRecord
{
    public static function tableName(): string
    {
        return 'sys_test_data';
    }

    public function rules(): array
    {
        return [
            [['user_id', 'struct_id'], 'required'],
            [['create_time', 'update_time'], 'safe'],
            [['title', 'remark'], 'string', 'max' => 255],
            [['status'], 'string', 'max' => 1],
        ];
    }

    public function attributeLabels(): array
    {
        return [
            'id' => 'ID',
            'user_id' => '用户id',
            'struct_id' => '部门id',
            'title' => 'Title',
            'remark' => 'Remark',
            'status' => 'Status',
            'create_time' => 'Create Time',
            'update_time' => 'Update Time',
        ];
    }

    public function behaviors(): array
    {
        return [
            [
                'class' => \yii\behaviors\TimestampBehavior::class,
                'attributes' => [
                    \yii\db\ActiveRecord::EVENT_BEFORE_INSERT => ['create_time', 'update_time'],
                    \yii\db\ActiveRecord::EVENT_BEFORE_UPDATE => ['update_time'],
                ],
                'value' => function () {
                    return (new \DateTime())->format('Y-m-d H:i:s');
                }
            ]
        ];
    }

    public function getUser(): ?\yii\db\ActiveQuery
    {
        return $this->hasOne(Admin::class, ['id' => 'user_id']);
    }

    public function getStruct(): ?\yii\db\ActiveQuery
    {
        return $this->hasOne(Struct::class, ['id' => 'struct_id']);
    }
}
